





package com.lanou3g.springcloud.hello.consumer.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

/**
 * Eureka服务注册中心常规调用方式
 */
@Slf4j
@Controller
@RequestMapping("/ribbon")
public class HelloRibbonController {

	@Autowired
	private RestTemplate restTemplate;

	@RequestMapping("/")
	public String defaultHello(Model model) {
		String url = "http://hello-server/";
		String result = restTemplate.getForObject(url, String.class);
		model.addAttribute("msg", result);
		return "index";
	}

	@RequestMapping("/name/{name}")
	public String nameHello(@PathVariable String name, Model model) {
		String url = "http://hello-server/name/"+name;
		String result = restTemplate.getForObject(url, String.class);
		model.addAttribute("msg", result);
		return "index";
	}

	@RequestMapping("/json/{name}")
	public String jsonHello(@PathVariable String name, Model model) {
		String url = "http://hello-server/json/"+name;
		String result = restTemplate.getForObject(url, String.class);
		model.addAttribute("msg", result);
		return "index";
	}

	/*@RequestMapping("/calc/{name}/{numA}/{numB}/{operator}")
	public String calcHello(String name, Integer numA, Integer numB, Integer operator) {


		//"Name:zhangsan, calc: 4*5=20";

		return null;
	}*/
}